/**
 * 
 * ETH AI GAME LIBRARY
 * 
 * Author: Michael Jaworski
 * Copyright (c) Michael Jaworski 2010
 * http://code.google.com/p/eth/
 * 
 * Licence Agreement
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *	
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

package lib.eth.core.types
{
	import flash.utils.getQualifiedClassName;
	
	/**
	 * a class that when extended can be used to create enumerations. the class
	 * hold integer values. If you log this class (very useful) it will output
	 * the class name and the ordinal you specified. the class does not
	 * store string equivalents for efficiency.
	 * 
	 * if you use this class with EthBitFlag then you need to make sure all of
	 * your ordinal values are positive powers of two (1, 2, 4, ...)
	 * 
	 * if you just need an enumeration the values can be anything
	 *
	 * @version 0.1
	 * @see lib.eth.core.types.EthBitFlag
	 * 
	 * 
	 * <pre>
	 * EthEnum Example
	 * 
	 * class ActionEnum extends EthEnum 
	 * {
	 *   public static const ATTACK:ActionEnum 		= new ActionEnum (ATTACK, 1);
	 *   public static const DEFEND:ActionEnum 		= new ActionEnum (DEFEND, 2);
	 *   public static const RELOAD:ActionEnum 		= new ActionEnum (RELOAD, 4);
	 *   public static const CALL_HELP:ActionEnum = new ActionEnum (CALL_HELP, 8);
	 *   public static const RETREAT:ActionEnum 	= new ActionEnum (RETREAT, 16);
	 * }
	 * </pre>
	 * 
	 */ 
	public class EthEnum
	{
		/**
		 * the value this constant holds
		 */		
		protected var _ordinal:int;
		
		/**
		 * stores just the ordinal; you can use this class to limit the values
		 * that a method may take as a parameter by passing in the class.
		 */ 
		public function EthEnum (enumIn:EthEnum, ordinalIn:int)
		{
			_ordinal = ordinalIn;
		}
		
		/**
		 * the value of the single enumeration constant
		 */ 
		public function get ordinal () : int
		{ return _ordinal; }
		
		/**
		 * cast the ordinal to a uint because we need uint for 
		 * the bit operations. if you are going to use the Enum with
		 * the BitFlag then you need to use power powers of two
		 */ 
		internal function get flag () : uint
		{ 
			return (uint)(_ordinal); 
		}		
		
		/**
		 * careful : this method accepts any EthEnum and so you could accidently
		 * cross values from one enum with another and they would match
		 * 
		 * @return true if the EthEnum holds the same value
		 */
		[Override]
		public function equals (ethIn:EthEnum) : Boolean
		{ return (_ordinal == ethIn._ordinal); }
		
		/**
		 * @return the name of the class with the ordinal wrapped in parenthesis
		 */
		public function toString () : String
		{
			return (getQualifiedClassName (this)) + '(' + _ordinal.toString () + ')';
		}		
	}
}